package com.byxy.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.byxy.model.User;
import com.byxy.service.UserService;



@Scope("prototype")
@Service("userService")
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class UserServiceImpl extends BaseServiceImpl implements UserService {
	/**
	 * 管理人员登录
	 * 
	 * @param userName
	 *            账号
	 * @param password
	 *            登陆密码
	 * @return
	 * @throws Exception
	 */
	public User findUser(String userName, String password) throws Exception {
		Object[] objs = { userName, password };
		List<User> list = getBaseDao().find(
				"select * from User du where du.username=? and du.password=?",
				objs);
		if (list != null && list.size() > 0) {
			return (User) list.get(0);
		} else {
			return null;
		}
	}
	/**
	 * 根据账号查找用户信息
	 * 
	 * @param userName
	 *            账号
	 * @param password
	 *            登陆密码
	 * @return
	 * @throws Exception
	 */
	public User findUser(String userName) throws Exception {
		Object[] objs = { userName};
		List<User> list = getBaseDao().find(
				"select du from User du where du.userName=?",
				objs);
		if (list != null && list.size() > 0) {
			return (User) list.get(0);
		} else {
			return null;
		}
	}

	
	
}
